package com.isaiah.algorithms.sort;

/**
 * @Title:
 * @Description:
 * @author: Haijun
 * @emial: isaiah@sohu.com
 * @date 2021/2/1709:48
 */
public class Shell {

    public static void sort(Comparable[] arr){
        // 确定h的初始值
        int h = 1;
        while (h < arr.length /2){
            h = 2*h+1;
        }
        while(h >= 1){
            for (int i = h; i < arr.length; i++){
                for (int j = i; j >= h; j-=h){
                    if (greater(arr[j-h], arr[j])){
                        swap(arr, j-h, j);
                    }else{

                        break;
                    }
                }
            }
            // 减少h的值
            h=h/2;
        }
    }
    public static void swap(Comparable[] arr, int i, int j){

    }

    public static boolean greater(Comparable v, Comparable w){
        return v.compareTo(w) > 0;
    }
}
